package ru.teleology.cubefs.api.models;

import java.io.PrintStream;

import ru.teleology.cubefs.api.reflection.IDValue;
import ru.teleology.cubefs.api.reflection.Types;

public class BasicJavaLogHandler extends AbstractJavaLogHandler {

	private PrintStream out;
	
	@Override
	public void begin(int level) {
		String start;
		
		if (level <= LogHandler.TRACE) {
			start = "TRACE";
			out = System.out;
		}
        else if (level <= LogHandler.DEBUG) {
        	start = "DEBUG";
			out = System.out;
        }
        else if (level <= LogHandler.INFO) {
        	start = "INFO";
			out = System.out;
        }
        else if (level <= LogHandler.WARN) {
        	start = "WARN";
			out = System.out;
        }
        else if (level <= LogHandler.ERROR) {
        	start = "ERROR";
			out = System.err;
        }
        else {
        	start = "FATAL";
			out = System.err;
        }
		
		out.print(start);
		out.print(" ");
	}

	@Override
	public void end() {
		out.println();
	}

	@Override
	public void log(boolean value) {
		out.print(value);
	}

	@Override
	public void log(byte value) {
		out.print(value);
	}

	@Override
	public void log(short value) {
		out.print(value);
	}

	@Override
	public void log(int value) {
		out.print(value);
	}

	@Override
	public void log(long value) {
		out.print(value);
	}

	@Override
	public void log(float value) {
		out.print(value);
	}

	@Override
	public void log(double value) {
		out.print(value);
	}

	@Override
	public void log(String value) {
		out.print(value);
	}

	@Override
	public void logId(long handle) {
		IDValue value = (IDValue) Types.getInstance(handle);
		out.print("ID:");
		out.print(value);
	}

	@Override
	public void logPtr(long value) {
		out.print("PTR:");
		out.print(value);
	}
}
